package projectVersion;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @description 资源文件加载器
 * @author lj
 * @createTime 2016年12月3日 下午3:56:59
 */
public abstract class ResLoader {
    public static enum State{
        START,END,RUNNING
    }
    public ResLoader(InputStream in) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String string = null;
        int count = 0;
        try {
            State state = State.RUNNING;
            while ((string = reader.readLine()) != null) {
                if (count == 0) {
                    state = State.START;
                }
                onReadLine(string.trim(),state);
                count ++;
            }
            onReadLine("",State.END);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null)
                    in.close();
                if (reader != null)
                    reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    abstract void onReadLine(String lineStr,State state);
}